Skip to main content

Payment Flow

To explain the payment flow, let's take a look at the following diagram:

console

1. Create Checkout Session

pip install notrix
from notrix import Client, CheckoutSessionLineItem

client = Client("SECRET_API_KEY", "PROJECT_ID")

checkout_session = client.create_checkout_session(
success_url="https://myshop.com/successful-payment",
cancel_url="https://myshop.com/payment-canceled",
items=[
CheckoutSessionLineItem(
name="Bike",
description="green bike",
price=28.2, # USD
quantity=1,
imageURL="https://images.com/bike",
)
]
)

print(checkout_session.link()) # Redirect the user to this payment page link in order to pay

2. Save Checkout Session to DB and Redirect

After creating the checkout session, save it to your DB and mark its status as pending. Now, redirect the user to the payment page link to proceed with the payment. Once the payment is confirmed, the user will be redirected to the success URL provided during the checkout session creation, And a webhook will be sent if configured.

3. Check Payment Status

After the user is redirected to the success URL, verify the payment confirmation by checking the status of the checkout session. Only then should you initiate the post-payment process.

danger

You MUST check the checkout session status before starting the post-payment process.

pip install notrix
from notrix import Client

client = Client("<SECRET_API_KEY>", "PROJECT_ID")

payment_confirmed = client.is_paid(checkout_session.paymentRequestToken) # True / False